package myPetStore.web.servlet;

import myPetStore.domain.Account;
import myPetStore.domain.Order;
import myPetStore.service.OrderService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class ListOrdersServlet extends HttpServlet {
    OrderService orderService;
    private static final String  LIST_ORDERS="/WEB-INF/jsp/order/listOrders.jsp";

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session=req.getSession();
        Account account=(Account) session.getAttribute("loginAccount");
        List<Order> orderList;
        orderService=new OrderService();
        orderList=orderService.getOrdersByUsername(account.getUsername());
        session.setAttribute("orderList",orderList);
        req.getRequestDispatcher(LIST_ORDERS).forward(req,resp);
    }
}
